package com.plant.plants.controller;

import com.plant.plants.domain.PlantResponse;
import com.plant.plants.services.PlantServices;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

@Controller
public class PlantController {

    //初始化查看页面
    @RequestMapping(value = "index", method = RequestMethod.GET)
    public Object index(Model model) {
        return "index";
    }

    //提交结果页面
    @RequestMapping(value = "index", method = RequestMethod.POST)
    public String upload(Model model, @RequestParam("file") MultipartFile file) throws Exception {
        PlantResponse response = new PlantServices().upload(file);
        model.addAttribute("plantInfo", response);
        model.addAttribute("maxResult", response.getDetectorResult().getName());
        return "index";
    }
}
